import server from "@/server/index.js";
// 获取播放历史足迹
const getSingleHistoryPromise = (psId) => {
    return new Promise((resolve) => {
        server
            .querySingleHistoryForLong({
                objectId: psId,
            })
            .then((res) => {
                console.log("detail getSingleHistoryPromise:code", res.code);
                if (
                    res.code === 0 &&
                    res.data?.objectId &&
                    res.data?.lastProgramId
                ) {
                    resolve(res.data);
                } else {
                    console.log("detail getSingleHistoryPromise:code", res.data?.objectId,  res.data?.lastProgramId);
                    resolve(false);
                }
            })
            .catch(() => {
                console.log("detail getSingleHistoryPromise:catch");
                resolve(false);
            });
    });
};
const getDetailDataPromise = (psId) => {
    return new Promise((resolve) => {
        server
            .getDetailInfoForLong(psId)
            .then((res) => {
                console.log("detail getDetailDataPromise", res?.code);
                if (res?.data?.id && res?.data?.sources) {
                    let { data, unSupportDefinitions, configs } = res;
                    let info = data;
                    info.unSupportDefinitions = unSupportDefinitions;
                    info.not_support_4k_msg = configs.not_support_4k_msg || "";
                    info.networkAudioVisualLogo =
                        configs.networkAudioVisualLogo || "";
                    info.licenseNumber =
                        info.licenseNumber && info.licenseNumber.length
                            ? info.licenseNumber
                            : [];
                    resolve(info);
                } else {
                    console.log(
                        "detail getDetailDataPromise:res",
                        res?.data?.id,
                        res?.data?.sources
                    );
                    resolve(false);
                }
            })
            .catch(() => {
                console.log("detail getDetailDataPromise:catch");
                resolve(false);
            });
    });
};

export default {
    getSingleHistoryPromise: getSingleHistoryPromise,
    getDetailDataPromise: getDetailDataPromise,
};
